package services;

import java.util.Collection;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import repositories.OwnershipRepository;
import domain.Customer;
import domain.Ownership;

@Service
@Transactional
public class OwnershipService {

	// Managed repository

	@Autowired
	private OwnershipRepository ownershipRepository;

	@Autowired
	private ActorService actorService;

	// Supporting services
	
	// Simple CRUD methods
	
	public void save(Ownership ownership) {
		Assert.isTrue(actorService.findByPrincipal() instanceof Customer);
		ownershipRepository.save(ownership);
		
	}
	
	// Other business methods

	public Collection<Ownership> findOwnershipByPaintingId(int paintingId){
		return ownershipRepository.findOwnershipByPaintingId(paintingId);
	}
	
	
}
